<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>gauss</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="gainslider.html" title="gainslider" />
    <link rel="next" href="gaussi.html" title="gaussi" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">gauss</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="gainslider.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="gaussi.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="gauss"></a>
      <div class="titlepage"></div>
      <a id="IndexGaussXClass" class="indexterm"></a>
      <a id="IndexGauss" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">gauss</span>
        </h2>
        <p>gauss — 
      Gaussian distribution random number generator.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp112245536"></a>
        <h2>Description</h2>
        <p>
      Gaussian distribution random number generator. This is an x-class noise generator.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp112312320"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>gauss</strong></span> krange</pre>
        <pre class="synopsis">ires <span class="command"><strong>gauss</strong></span> krange</pre>
        <pre class="synopsis">kres <span class="command"><strong>gauss</strong></span> krange</pre>
      </div>
      <div class="refsect1">
        <a id="idp112317152"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>krange</em></span> -- the range of the random numbers (-<span class="emphasis"><em>krange</em></span> to +<span class="emphasis"><em>krange</em></span>). Outputs both positive and negative numbers.
    </p>
        <p>
      <span class="emphasis"><em>gauss</em></span> returns random numbers following a normal distribution centered around 0.0 (mu = 0.0) with a variance (sigma) of <span class="emphasis"><em>krange</em></span> / 3.83. Thus more than 99.99%
      of the random values generated are in the range -<span class="emphasis"><em>krange</em></span> to +<span class="emphasis"><em>krange</em></span>. If a mean value different of 0.0 is desired, this mean value has to
      be added to the generated numbers (see example below).
    </p>
        <p>
      For more detailed explanation of these distributions, see:
      </p>
        <div class="orderedlist">
          <ol class="orderedlist" type="1">
            <li class="listitem">
              <p>C. Dodge - T.A. Jerse 1985. Computer music. Schirmer books. pp.265 - 286</p>
            </li>
            <li class="listitem">
              <p>D. Lorrain. A panoply of stochastic cannons. In C. Roads, ed. 1989. Music machine . Cambridge, Massachusetts: MIT press, pp. 351 - 379.</p>
            </li>
          </ol>
        </div>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp112325360"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the gauss opcode. It uses the file <a class="ulink" href="examples/gauss.csd" target="_top"><em class="citetitle">gauss.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp112327216"></a>
          <p class="title">
            <strong>Example 342. Example of the gauss opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
  -d -o dac
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="oblock">instr</span> 1
irange   <span class="op">=</span> p4
imu      <span class="op">=</span> p5
isamples <span class="op">=</span> p6
indx     <span class="op">=</span> 0
icount   <span class="op">=</span> 1
ix       <span class="op">=</span> 0.0
ix2      <span class="op">=</span> 0.0

<span class="olabel">loop</span><span class="op">:</span>
i1       <span class="opc">gauss</span>   irange
i1       <span class="op">=</span>       i1 <span class="op">+</span> imu
ix       <span class="op">=</span>       ix <span class="op">+</span> i1
ix2      <span class="op">=</span>       ix2 <span class="op">+</span> i1<span class="op">*</span>i1
<span class="octrl">if</span> i1 <span class="op">&gt;=</span> <span class="op">-</span>(irange<span class="op">+</span>imu) <span class="op">&amp;&amp;</span> i1 <span class="op">&lt;=</span> (irange<span class="op">+</span>imu) then
  icount <span class="op">=</span> icount<span class="op">+</span>1
<span class="octrl">endif</span>
         <span class="octrl">loop_lt</span> indx, 1, isamples, <span class="olabel">loop</span>
        
imean    <span class="op">=</span>       ix <span class="op">/</span> isamples                         <span class="comment">;mean value</span>
istd     <span class="op">=</span>       <span class="opc">sqrt</span>(ix2<span class="op">/</span>isamples <span class="op">-</span> imean<span class="op">*</span>imean)      <span class="comment">;standard deviation</span>
         <span class="opc">prints</span> "mean <span class="op">=</span> <span class="op">%</span>3.3f, std <span class="op">=</span> <span class="op">%</span>3.3f, ", imean, istd
         <span class="opc">prints</span> "samples inside the given range<span class="op">:</span> <span class="op">%</span>3.3f\<span class="op">%</span>\n", icount<span class="op">*</span>100.0<span class="op">/</span>isamples
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0   0.1 1.0   0   100000  <span class="comment">; range = 1, mu = 0.0, sigma = 1/3.83 = 0.261</span>
<span class="stamnt">i</span> 1 0.1 0.1 3.83  0   100000  <span class="comment">; range = 3.83, mu = 0.0, sigma = 1</span>
<span class="stamnt">i</span> 1 0.2 0.1 5.745 2.7 100000  <span class="comment">; range = 5.745, mu = 2.7, sigma = 5.745/3.83 = 1.5</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />

      Its output should include lines like this:
      </p>
        <pre class="screen">
mean = 0.000, std = 0.260, samples inside the given range: 99.993%
mean = 0.005, std = 0.999, samples inside the given range: 99.998%
mean = 2.700, std = 1.497, samples inside the given range: 100.000%</pre>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp112332432"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="seed.html" title="seed"><em class="citetitle">seed</em></a>,
      <a class="link" href="betarand.html" title="betarand"><em class="citetitle">betarand</em></a>,
      <a class="link" href="bexprnd.html" title="bexprnd"><em class="citetitle">bexprnd</em></a>,
      <a class="link" href="cauchy.html" title="cauchy"><em class="citetitle">cauchy</em></a>,
      <a class="link" href="exprand.html" title="exprand"><em class="citetitle">exprand</em></a>,
      <a class="link" href="linrand.html" title="linrand"><em class="citetitle">linrand</em></a>,
      <a class="link" href="pcauchy.html" title="pcauchy"><em class="citetitle">pcauchy</em></a>,
      <a class="link" href="poisson.html" title="poisson"><em class="citetitle">poisson</em></a>,
      <a class="link" href="trirand.html" title="trirand"><em class="citetitle">trirand</em></a>,
      <a class="link" href="unirand.html" title="unirand"><em class="citetitle">unirand</em></a>,
      <a class="link" href="weibull.html" title="weibull"><em class="citetitle">weibull</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp112344112"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Paris Smaragdis</td>
          </tr>
          <tr>
            <td>MIT, Cambridge</td>
          </tr>
          <tr>
            <td>1995</td>
          </tr>
        </table>
        <p>
    </p>
        <p>Precisions about mu and sigma added by François Pinot after a discussion with
    Joachim Heintz on the Csound List, December 2010.</p>
        <p>Example written by François Pinot, adapted from a csd file by Joachim Heintz, December 2010.</p>
        <p>Existed in 3.30</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="gainslider.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="gaussi.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">gainslider </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> gaussi</td>
        </tr>
      </table>
    </div>
  </body>
</html>
